package view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by ThinkPad on 2017/5/5.
 */

public class CirleView extends View {

    public CirleView(Context context) {
        super(context);
    }

    public CirleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CirleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    int l;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width  = getMeasuredWidth();
        int height = getMeasuredHeight();
        if(width<height) {
            l = width;
            setMeasuredDimension(width, width);
        }else{
            l = height;
            setMeasuredDimension(height, height);
        }
    }


    @Override
    protected void onDraw(Canvas canvas) {
        Paint mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(new Color().argb(51, 51,133,255));
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(l / 2, l / 2, l/2, mPaint);
        super.onDraw(canvas);
    }
}
